package com.cat.slidingWindow;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author cat
 * @description https://leetcode.cn/problems/maximum-erasure-value/
 * @create 2025/7/29 11:15
 * @since JDK17
 */

public class Solution08 {
    static int[] h = new int[1001];
    public int maximumUniqueSubarray(int[] nums) {
        Arrays.fill(h, 0);
        int ans = 0, n = nums.length, sum = 0, cnt, t;
        for (int l = 0, r = 0; r < n; r++) {
            sum += nums[r];
            h[nums[r]]++;
            while (h[nums[r]] > 1) {
                sum -= nums[l];
                h[nums[l++]]--;
            }
            ans = Math.max(ans, sum);
        }
        return ans;
    }
}
